import Request from '@/libs/request'
import {getSession} from '@/libs/sessionStorage'
import {selectDictItemByCode} from './dict'

// 指标库--查询 所有
export const selectTargetLibByPage = (
  data: {targetLibTypeCode?: string; targetLibName?: string; pmDimensionTypeCode?: string} & Paging
) =>
  Request.get<PagingResponse<PmTargetLib.TargetLibData>>('/targetLib/selectTargetLibByPage', data)

// 指标库--查询 单个
export const selectTargetLibByTargetLibId = (data: {targetLibId: number}) =>
  Request.get<PmTargetLib.TargetLibData>('/targetLib/selectTargetLibByTargetLibId', data)

// 指标库分类--查询
export const selectTargetLibTypeByTypeCode = () =>
  selectDictItemByCode<'007', string>({typeCode: '007'})

// 指标库类型--查询
export const selectPmDimensionTypeByTypeCode = () =>
  selectDictItemByCode<'006', string>({typeCode: '006'})

// 指标库类型--添加
export const addSysDictItem = (data: {dictName: string}) =>
  Request.get<null>('/type/addSysDictItem', Object.assign({dictTypeCode: '007'}, data))

// 指标库类型--修改
export const editDictItemByCode = (data: {dictCode: string; dictName: string}) =>
  Request.get<null>('/type/editDictItemByCode', data)

// 指标库类型--删除
export const deleteTargetLibType = (data: {dictCode: string}) =>
  Request.get<null>('/type/deleteSysDictItem', Object.assign({dictTypeCode: '007'}, data))

// 指标库类型--添加
export const deleteTargetLib = (data: {targetLibId: number}) => {
  const userDDId = getSession('userDDId')
  if (!userDDId) return Promise.reject(false)
  Object.assign(data, {userDDId})
  return Request.get<null>('/targetLib/deleteTargetLib', data)
}

// 指标库--添加
export const addTargetLib = (data: PmTargetLib.TargetLibDataByAdd) =>
  Request.get<null>('/targetLib/addTargetLib', data)

// 指标库--修改
export const editTargetLib = (data: PmTargetLib.TargetLibDataByEdit) =>
  Request.get<null>('/targetLib/editTargetLib', data)
